package com.witsight.hibernate.dao;

import java.io.Serializable;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;


/**   
 * 说明：创建自己封装的工厂类。<br/>可以动态语句查询能功能的扩展
 * @Title: CustomJpaRepositoryFactoryBean.java 
 * @Package com.witsight.hibernate.dao 
 * @See: {@link JpaRepositoryFactoryBean}
 * Copyright: Copyright (c) 2017
 * Company:sany huax witsight team by product
 * @author: fuyp  
 * @date: 2017年9月14日 下午2:28:33 
 * @version: V1.0
 *
 */
public class CustomJpaRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>  extends JpaRepositoryFactoryBean<T, S, ID> {
	/**
     * Logger
     */
    private static final Logger log = LoggerFactory.getLogger(CustomJpaRepositoryFactoryBean.class);
	@Autowired
	private EntityManagerFactory sessionFactory;
	@Autowired
	private JpaCommonRepository commonRepository;
    /**
     * 
     * 说明：构造函数 
     * @Title:CustomJpaRepositoryFactoryBean.java
     * @See: 构造函数 
     * @param repositoryInterface
     * @date Jun 13, 2017 8:20:03 PM
     */
	public CustomJpaRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
		super(repositoryInterface);
	}
	/**
	 * 创建自己封装的工厂类。
	 * (non-Javadoc)  
	 * @Title: createRepositoryFactory
	 * @See: 
	 * @author fuyp 
	 * @param entityManager 实体管理器
	 * @return RepositoryFactorySupport工厂类
	 * @date: 2015年4月22日 下午12:15:33
	 */
	protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
		if (log.isInfoEnabled()) {
			log.info("CustomJpaRepositoryFactory be instanced.");
		}
		CustomJpaRepositoryFactory factory = new CustomJpaRepositoryFactory(entityManager , sessionFactory , commonRepository);
		return factory;
	}
}
